<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div *ngIf="alertNotifier" class="gv-page-container">
  <a [routerLink]="['..']" class="gv-back-link"><small><< Back to alert notifiers</small></a>
  <h1>{{alertNotifier.name}}</h1>
  <div class="gv-page-content">
    <div fxLayout="column">
      <div *ngIf="notifierSchema && notifierSchema.description" class="notifier-contextual-help">
        <pre [innerHTML]="notifierSchema?.description"></pre>
      </div>
      <div fxLayout="row">
        <div fxLayout="column" fxFlex="70">
          <form #alertNotifierForm="ngForm">
            <div class="gv-form-section">
              <mat-form-field appearance="outline" floatLabel="always">
                <mat-label>Name</mat-label>
                <input matInput type="text" placeholder="Name" name="name" [(ngModel)]="alertNotifier.name" required>
                <mat-hint>Notifier name</mat-hint>
              </mat-form-field>
            </div>

            <div class="gv-form-section">
              <div class="gv-form-section-title">
                <h5>Configuration</h5>
                <mat-divider></mat-divider>
              </div>
              <div>
                <alert-notifier-form *ngIf="alertNotifier" [notifierConfiguration]="alertNotifierConfiguration"
                                     [notifierSchema]="notifierSchema"
                                     (configurationCompleted)="enableProviderUpdate($event)"></alert-notifier-form>
              </div>
            </div>
            <div *hasPermission="['domain_alert_notifier_update']" fxLayout="row">
              <button mat-raised-button
                      [disabled]="(!alertNotifierForm.valid || alertNotifierForm.pristine) && (!configurationIsValid || configurationPristine)"
                      (click)="update()">SAVE
              </button>
            </div>
          </form>

          <div *hasPermission="['domain_alert_notifier_delete']" class="gv-page-delete-zone" fxLayout="column">
            <p>This operation cannot be undone.</p>
            Alert notifier will be deleted, alert notification will not be sent using this notifier anymore.
            <div fxLayout="row">
              <span fxFlex></span>
              <button mat-raised-button color="warn" (click)="delete($event)">DELETE</button>
            </div>
          </div>
        </div>
        <div class="gv-page-description" fxFlex="30">
          <h3>Manage alert notifier</h3>
          <div class="gv-page-description-content">
            <p>
              Configure your alert notifier to be able to receive your alerts on the channel of your choice.
            </p>
            <small>You can also customize the alert message and use your notifier to just one type of alert</small>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
